// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Category.java

package include.treeview;

import include.nseer_db.nseer_db;
import include.tree_index.businessComment;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;

// Referenced classes of package include.treeview:
//			TreeviewElement

public class Category
	implements TreeviewElement
{

	protected int ID;
	protected int parentID;
	private String mod;
	private String sql1;
	private String human_ID;
	private String dbase;
	protected String categoryName;
	private String categoryTemp;
	private businessComment demo;
	protected String categoryUrl;
	protected String activeStatus;
	private HttpServletRequest request;

	public Category()
	{
		activeStatus = "Y";
		ID = -1;
	}

	public Category(int id, String mod, String human_ID, String dbase, HttpServletRequest request)
	{
		activeStatus = "Y";
		this.request = request;
		ID = id;
		this.mod = mod;
		this.human_ID = human_ID;
		this.dbase = dbase;
		demo = new businessComment();
		demo.setPath(request);
		if (!FromDb())
			ID = -1;
	}

	public boolean FromDb()
	{
		String group_name;
		nseer_db demoa;
		ResultSet rs;
		int row = -1;
		categoryTemp = (new StringBuilder(String.valueOf(mod))).append("_view").toString();
		group_name = "erp";
		demoa = new nseer_db(dbase);
		if (ID == 0)
			sql1 = (new StringBuilder("select * from ")).append(categoryTemp).append(" where category_id=").append(ID).append(" and active_status='Y'").toString();
		else
			sql1 = (new StringBuilder("select * from ")).append(categoryTemp).append(" where category_id=").append(ID).append(" and active_status='Y' and HUMAN_ID='").append(human_ID).append("'").toString();
		rs = demoa.executeQuery(sql1);
		rs.last();
		int row = rs.getRow();
		if (row != 1)
			break MISSING_BLOCK_LABEL_242;
		parentID = rs.getInt("PARENT_CATEGORY_ID");
		categoryName = demo.getLang(group_name, rs.getString("MODULE_NAME"));
		categoryUrl = rs.getString("HREFLINK");
		activeStatus = rs.getString("ACTIVE_STATUS");
		demoa.close();
		return true;
		try
		{
			demoa.close();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
			return false;
		}
		return false;
	}

	public String getActiveStatus()
	{
		return activeStatus;
	}

	public void setActiveStatus(String activeStatus)
	{
		this.activeStatus = activeStatus;
	}

	public String getCategoryName()
	{
		return categoryName;
	}

	public String getCategoryUrl()
	{
		return categoryUrl;
	}

	public void setCategoryName(String categoryName)
	{
		this.categoryName = categoryName;
	}

	public void setCategoryUrl(String categoryUrl)
	{
		this.categoryUrl = categoryUrl;
	}

	public int getID()
	{
		return ID;
	}

	public void setID(int id)
	{
		ID = id;
	}

	public int getParentID()
	{
		return parentID;
	}

	public void setParentID(int parentID)
	{
		this.parentID = parentID;
	}

	public String getNodeName()
	{
		return getCategoryName();
	}

	public String getNodeUrl()
	{
		return getCategoryUrl();
	}

	public boolean canExpand()
	{
		nseer_db democ;
		ResultSet rs;
		democ = new nseer_db(dbase);
		String sql = (new StringBuilder("select category_id from ")).append(categoryTemp).append(" where parent_category_id=").append(getID()).append(" and HUMAN_ID='").append(human_ID).append("'").toString();
		rs = democ.executeQuery(sql);
		int row;
		rs.last();
		row = rs.getRow();
		democ.close();
		return row > 0;
		SQLException e;
		e;
		e.printStackTrace();
		return false;
	}

	public TreeviewElement[] getChildren()
	{
label0:
		{
			nseer_db demob = new nseer_db(dbase);
			String sql = (new StringBuilder("select category_id from ")).append(categoryTemp).append(" where parent_category_id=").append(getID()).append(" and HUMAN_ID='").append(human_ID).append("'").toString();
			ResultSet rs = demob.executeQuery(sql);
			Vector vData;
			TreeviewElement children[];
			int i;
			int id;
			try
			{
				rs.last();
				int row = rs.getRow();
				if (row > 0)
					break label0;
				demob.close();
			}
			catch (SQLException e)
			{
				e.printStackTrace();
				return null;
			}
			return null;
		}
		vData = new Vector();
		rs.beforeFirst();
		for (; rs.next(); vData.add((new StringBuilder()).append(rs.getInt("CATEGORY_ID")).toString()));
		children = new TreeviewElement[vData.size()];
		for (i = 0; i < vData.size(); i++)
		{
			id = Integer.parseInt((String)vData.get(i));
			children[i] = new Category(id, mod, human_ID, dbase, request);
		}

		demob.close();
		return children;
	}
}
